package web;

import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.DBtools;

import org.mariadb.jdbc.Statement;
/**
 * Servlet implementation class ServletUpdateTeaInfo
 */
@WebServlet("/ServletUpdateTeaInfo")
public class ServletUpdateTeaInfo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletUpdateTeaInfo() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String teaId = request.getParameter("id");
		String teaName = request.getParameter("name");
		String teaGender = request.getParameter("sex");
		String email = request.getParameter("email");
		String teaage = request.getParameter("age");
		String depName = request.getParameter("dep");




		//构造写入数据库sql
		String sql = "";
		
	    sql= "update teacher set TeaId='"+teaId+"',TeaName='"+teaName+"',TeaGender='"+teaGender+"',TeaEmail='"+email+"',TeaAge='"+teaage+"',DepName='"+depName+"' where TeaId = " + teaId ;
		
	
		System.out.println("TeacherSave() sql=" + sql); 

		//连接数据库

		try{
			int ret = DBtools.execute(sql);
			System.out.println("ret=" + ret);	
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}

		//返回页面
		response.sendRedirect("teacherclock/teacherinfo.jsp");
	}

}
